using System;
using PostSharp.Extensibility;

namespace CriticalSystems.Instrumentation
{
    [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class |
        AttributeTargets.Method | AttributeTargets.Constructor,
        AllowMultiple = true, Inherited = false)]
    [MulticastAttributeUsage(MulticastTargets.Method | MulticastTargets.Constructor, AllowMultiple = true)]
    public sealed class LoggingAttribute : MulticastAttribute, IRequirePostSharp
    {
        private string name;
        private LoggingType loggingType = LoggingType.LogAbnormalExit;

        /// <summary>
        /// Gets/sets the, optional, boundary name.
        /// </summary>
        public string Name
        {
            get { return this.name; }
            set { this.name = value; }
        }

        public LoggingType LoggingType
        {
            get { return this.loggingType;}
            set { this.loggingType = value;}
        }

        #region IRequirePostSharp Members
        /// <summary>
        /// Returns the requirements of the current attribute in the post-compilation process.
        /// </summary>
        /// <returns>A <see cref="PostSharpRequirements"/> object meaning that the 
        /// task named <b>SampleTrace</b> is required.</returns>
        PostSharpRequirements IRequirePostSharp.GetPostSharpRequirements()
        {
            PostSharpRequirements requirements = new PostSharpRequirements();
            requirements.PlugIns.Add("CriticalSystems.Instrumentation");
            requirements.Tasks.Add("CriticalSystems.Instrumentation");
            return requirements;
        }
        #endregion
    }

    /// <summary>
    /// Defines the type of logging associated with a logging attribute.
    /// </summary>
    [Flags]
    public enum LoggingType
    {
        LogEntry = 1,
        LogExit = 2,
        LogAbnormalExit = 4
    }
}